package cs6238.common.message.response;

import java.nio.ByteBuffer;

import cs6238.common.message.MessageId;

/**
 * The standard response used for most of the commands
 * Has a boolean result, that communicates the state of the command
 */
public class StandardResponse extends Response{
	
	private boolean _ok;
	
	public StandardResponse(boolean value){
		_ok = value;
	}
	
	public StandardResponse(){
		_ok = false;
	}
	
	public byte[] serialize(){		
		ByteBuffer bb = ByteBuffer.allocate(4 + 1);
		bb.putInt(MessageId.STANDARD_RESPONSE.ordinal());
	
		bb.put((byte) (_ok ? 1 : 0));
	
		return bb.array();
	}
	
	public void deserialize(byte[] buffer){
		ByteBuffer bb = ByteBuffer.wrap(buffer);
		bb.getInt();
		
		_ok = (bb.get() == 1);
	}
	
	public boolean isOk(){
		return _ok;
	}
}
